package service;

import dao.CategoryDao;
import model.Category;

import java.sql.SQLException;
import java.util.List;

public class CategoryService {
    CategoryDao cDao=new CategoryDao();
    //获取所有类型
    public List<Category> GetAllType()
    {
        List<Category> list=null;
        try {
            list=cDao.GetAllType();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    //根据类型id获取类型name
    public Category selectTypeNameByID(int category_id)
    {
        Category c=null;
        try {
            c=cDao.selectTypeNameByID(category_id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return c;
    }
    //根据id获取类型category
    public Category select(int id) {
        Category c=null;
        try {
            c = cDao.select(id);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return c;
    }
    //插入新的类型
    public void insert(Category c) {
        try {
            cDao.insert(c);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    //更新类型c
    public void update(Category c) {
        try {
            cDao.update(c);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    //根据id删除类型，成功返回true
    public boolean delete(int id) {
        try {
            cDao.delete(id);
            return true;
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }
    }
}

